

package jetbrains.buildServer.server.rest.data.change;

import jetbrains.buildServer.serverSide.ChangeDescriptor;
import jetbrains.buildServer.vcs.SVcsModification;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class SVcsModificationOrChangeDescriptor {
  private final SVcsModification myModification;
  private final ChangeDescriptor myChangeDescriptor;

  public SVcsModificationOrChangeDescriptor(@NotNull SVcsModification modification) {
    myChangeDescriptor = null;
    myModification = modification;
  }

  /**
   * descriptor.getRelatedVcsChange must be non-null;
   *
   * @param descriptor
   */
  public SVcsModificationOrChangeDescriptor(@NotNull ChangeDescriptor descriptor) {
    if(descriptor.getRelatedVcsChange() == null)
      throw new IllegalArgumentException();

    myChangeDescriptor = descriptor;
    myModification = descriptor.getRelatedVcsChange();
  }

  @NotNull
  public SVcsModification getSVcsModification() {
    return myModification;
  }

  @Nullable
  public ChangeDescriptor getChangeDescriptor() {
    return myChangeDescriptor;
  }

  @Override
  public String toString() {
    if(myChangeDescriptor != null) {
      return "SVMOCD{descriptor= " + myChangeDescriptor + " }";
    }
    return "SVMOCD{mod= " + myModification + " }";
  }
}